//
//  ClubGameDetailToolViewController.swift
//  77Club
//
//  Created by Apple on 2024/11/15.
//

import UIKit
import JXSegmentedView

class ClubGameDetailToolViewController: ClubBaseViewController, UITableViewDelegate, UITableViewDataSource {

    private lazy var tableView: UITableView = {
        let tableView = UITableView()
        tableView.delegate = self
        tableView.dataSource = self
        tableView.backgroundColor = .clear
        tableView.showsVerticalScrollIndicator = false
        tableView.register(ClubGameToolsListCell.self)
        tableView.contentInsetAdjustmentBehavior = .never
        tableView.separatorStyle = .none
        tableView.rowHeight = 92.0.Scale
        return tableView
    }()

    private var imgArray = ["Home_gameTools_0","Home_gameTools_1","Home_gameTools_2"]
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.subviews{
            tableView
        }

        tableView.fillContainer()
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return imgArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "ClubGameToolsListCell", for: indexPath) as! ClubGameToolsListCell
        cell.contentImg.image = imgArray[indexPath.row].toImage
        return cell
        
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        if let uid = UserDefaultsManager.getString(forKey: .uid), uid.count > 0 {
            
            var urlString = ""
            var title = ""
            if indexPath.row == 0 {
                title = "卡组库"
                urlString = "https://h5-tool.77.top/#/homePackages/cardGroup?token=" + uid
            }else if indexPath.row == 1 {
                title = "卡牌图鉴"
                urlString = "https://h5-tool.77.top/#/homePackages/cardGuid?token=" + uid
            }else if indexPath.row == 2 {
                title = "卡组模拟"
                urlString = "https://h5-tool.77.top/#/pages/cardGroup/index?token=" + uid
            }
            
            urlString = urlString + "&model=ios"
            
            let webView = ClubGameToolsWebViewController()
            webView.urlString = urlString
            webView.titleName = title
            self.navigationController?.pushViewController(webView, animated: true)
        }else{
            self.navigationController?.pushViewController(ClubLoginViewController(), animated: true)
        }
        
    }

}

extension ClubGameDetailToolViewController:JXSegmentedListContainerViewListDelegate {
    func listView() -> UIView {
        return view
    }
}
